<?php

namespace App\V3\V3_2_7\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AuditImagesModel extends Model
{
    use HasFactory;

    protected $table = 'audit_images';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    /**
     * 默认使用时间戳戳功能
     *
     * @var bool
     */
    public $timestamps = true;
    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    
    /**
     * 审核图片通过
     */
    static public function pass($data)
    {
        $idArr = array_filter(explode(',',$data['ids']),
                function($v) { return $v !== '';});
        $bool = false;
        if(is_array($idArr) && count($idArr)>0){
            DB::beginTransaction();
            try {
                SELF::whereIn('id',$idArr)
                ->where(['check_flag'=>0])
                ->update(['check_flag'=>1]);
                DB::commit();
                return $bool = true;
            } catch (\Exception $e) {
                DB::rollBack();
                Log::debug('取消标示用户异常：'.var_export($e->getMessage(),true));
            }
        }
        return $bool;
    }
}
